package com.apes.hr.transfer.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.base.model.Employee;
import com.apes.hr.base.model.WorkPost;
import com.apes.hr.transfer.model.QuitJobOrder;
import com.apes.scm.masterdata.frame.model.Branch;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @author HuJianLin
 * @create 2018-04-28 16:07
 */
public interface QuitJobOrderRepository extends CustomRepository< QuitJobOrder, String> {

    List< QuitJobOrder> findByIdAndState(String id, String state);

    List< QuitJobOrder> findByState( String state);

    @Query(value = "select A.* from hr_quit_job_order A " +
            "where A.state = ?1 AND A.real_last_day <= to_date(?2,'yyyy-MM-dd')", nativeQuery = true)
    List<QuitJobOrder> findByStateAndRealLastDay(String state, String lastDay);


    List<QuitJobOrder> findAllByStateEqualsAndRealLastDayLessThan(String state, Date realDate);

    @Query(value = "SELECT A.* FROM hr_quit_job_order A WHERE A.employee_id = ?1 AND (A.state = 'create' OR A.state = 'approve' OR A.state='disposing' OR a.state ='finish')",nativeQuery = true)
    List<QuitJobOrder> findByEmployeeAndState(Employee employee);

    @Query(value = "SELECT A.* FROM hr_quit_job_order A WHERE A.employee_id = ?1 AND (A.state = 'create' OR A.state = 'approve' OR A.state='disposing' )",nativeQuery = true)
    List<QuitJobOrder> findByEmployeeAndState2(Employee employee);

    List<QuitJobOrder> findByEmployee(Employee employee);

    List<QuitJobOrder> findByWorkBranchAndPostAndState(Branch branch, WorkPost workPost, String state);
}
